/**
 * 
 */
package info.niwota.web.proxy;

import info.niwota.web.servlet.WebdavHandler;




/**
 * @author qiangli
 *
 */
public class ProxyServer {
	private int port;
	private RequestListenerThread thread;
	private ProxyHandler proxy;

	public ProxyServer(int port, ProxyHandler proxy) {
		this.port = port;
		this.proxy = proxy;
	}
	
	public void startup() throws Exception {
		thread = new RequestListenerThread(port);
		//
		WebdavHandler webdav = new WebdavHandler();
		thread.register("/webdav*", webdav);
		thread.register("*", proxy);

		thread.setDaemon(true);
		thread.start();
	}
	
	public void shutdown() {
		if (thread != null) {
			thread.interrupt();
		}
		thread = null;
	}
	
	public int getPort() {
		return port;
	}
}
